package net.oschina.app.adapter.me.messageAdapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.base.BaseListAdapter;
import net.oschina.app.base.Global;
import net.oschina.app.bean2.ActiveBean;
import net.oschina.app.ui.activity.DetailActivity;

/**
 * Created by Shinelon on 2017/1/15.
 */

public class CommentListAdapter extends BaseListAdapter<ActiveBean> {
    private String mUrl;
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(Global.mContext).inflate(R.layout.item_me_message_comment,parent,false);
        CommentHolder holder = new CommentHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ActiveBean  data =  mList.get(position);

        ((CommentHolder)holder).tvAuthor.setText(data.getAuthor());
        ((CommentHolder)holder).tvPubDate.setText(data.getPubDate());
//        ((CommentHolder)holder).tvBody.setText(data.get());
        String message = data.getMessage();
        //富文本的显示
        Spanned html = Html.fromHtml(message);
        ((CommentHolder)holder).tvMsg.setText(html);
        mUrl = data.getUrl();

    }

    class CommentHolder extends RecyclerView.ViewHolder{
        public TextView tvAuthor;
        public TextView tvPubDate;
        public TextView tvMsg;
        public TextView tvBody;

        public CommentHolder(View itemView) {
            super(itemView);
            tvAuthor = (TextView) itemView.findViewById(R.id.tv_comment_coauthor);
            tvPubDate = (TextView) itemView.findViewById(R.id.tv_comment_copubDate);
            tvMsg = (TextView) itemView.findViewById(R.id.tv_comment_comsg);
            tvBody = (TextView) itemView.findViewById(R.id.tv_comment_cobody);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Global.mContext, DetailActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.putExtra("url",mUrl);
                    Global.mContext.startActivity(intent);
                }
            });
        }
    }
}
